package com.learning.springboot.trace.skywalking.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author Sam
 */
@EnableAutoConfiguration
@RestController
public class Backend {

    @RequestMapping("/api")
    public String printDate(@RequestHeader(name = "user_name", required = false) String username) {
        if (username != null) {
            return new Date().toString() + " " + username;
        }
        return new Date().toString();
    }

    public static void main(String[] args) {
        SpringApplication.run(Backend.class,
                "--spring.application.name=backend",
                "--server.port=9000"
        );
    }
}